<template>
  <view>
    <view class="goods-list">
      <view class="goods-item">
        <!-- 左边 -->
        <view class="goods-item-left">
          <!-- 购物车的复选框 -->
          <radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
          <!-- 图片 -->
          <image :src="goods.goods_small_logo" mode=""></image>
        </view>
        <!-- 右边 -->
        <view class="goods-item-right">
          <!-- 商品名称 -->
          <view class="goods-name">{{goods.goods_name}}</view>
          <view class="goods-info-box">
            <!-- 商品价格 -->
            <view class="goods-price">￥{{goods.goods_price | tofixed}}</view>
            <!-- 购物车的数字框 -->
            <uni-number-box v-if="showRadio" :min="1" :max="100" :value="goods.goods_count" @change="numBoxChange" />
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props: {
      // 商品
      goods: {
        type: Object,
        default: {}
      },
      // 是否展示复选框
      showRadio: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {

      };
    },
    methods: {
      radioClickHandler() {
        // 创建并触发一个自定义事件
        this.$emit('radio-change', {
          goods_state: !this.goods.goods_state,
          goods_id: this.goods.goods_id
        })
      },
      numBoxChange(value) {
        this.$emit('num-box-change', {
          goods_count: value,
          goods_id: this.goods.goods_id
        })
      }
    }

  }
</script>

<style lang="scss">
  .goods-list {
    .goods-item {
      // 让 goods-item 项占满整个屏幕的宽度
      width: 750rpx;
      // 设置盒模型为 border-box
      box-sizing: border-box;

      display: flex;
      justify-content: space-between;
      padding: 10px 5px;
      border-bottom: 1px solid #f0f0f0;

      // 图片
      .goods-item-left {
        margin-right: 5px;
        display: flex;
        align-items: center;
        justify-content: space-between;

        image {
          width: 100px;
          height: 100px;
          display: block;
        }
      }

      // 右边
      .goods-item-right {
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        // 商品名称
        .goods-name {
          font-size: 13px;
        }

        .goods-info-box {
          display: flex;
          justify-content: space-between;
          // 数字输入框

          // 价格
          .goods-price {
            font-size: 16px;
            color: #c00000;
          }
        }

      }
    }
  }
</style>
